package xyz.lwm.lazycat.mybatisflex;

import org.apache.ibatis.session.TransactionIsolationLevel;
import org.apache.ibatis.transaction.Transaction;
import org.apache.ibatis.transaction.TransactionFactory;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * mybatis transaction factory, 前提是引入了事务管理的数据源, 然后使用 mybatis 事务管理
 *
 * @author lwm
 */
public class LazycatTransactionFactory implements TransactionFactory {

    @Override
    public Transaction newTransaction(Connection conn) {
        throw new UnsupportedOperationException("newTransaction(Connection) method is not supported");
    }

    /**
     * new transaction
     *
     * @param dataSource 事务管理数据源
     * @return transaction
     */
    @Override
    public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
        return new LazycatTransaction(dataSource);
    }

}
